//不让别人引用
if (window != top) top.location.href = location.href;

layui.use(['form','layer'],function () {
    var form = layui.form;
    var layer = layui.layer;
    /**
     * 获取验证码
     * 将验证码写到login.html页面的id = verifyimg 的地方
     */
    $("#verifyImg").attr('src',timestamp("verifyCode"));
    getvCode = function getvCode() {
        $("#verifyImg").attr('src',timestamp("verifyCode"));
    }
    //为url添加时间戳
    function timestamp(url) {
        var getTimestamp = new Date().getTime();
        if (url.indexOf("?") > -1) {
            url = url + "&timestamp=" + getTimestamp
        } else {
            url = url + "?timestamp=" + getTimestamp
        }
        return url;
    };


    $("#login").on('click',function(){
        isVerify();
    })
    function isVerify(){
        var code = $('#verity').val();

        if(code==null||code==''){
            layer.msg("请输入验证码");
        }else{
            $.ajax({
                url:'/login/isVerify',
                type:'post',
                dataType:'json',
                data:{'code':code},
                success:function (data) {
                    if (data.data){
                        $('#goLogin').click();
                    }else {
                        layer.msg("验证码有误");
                        getvCode();
                        $('#verity').val('');
                    }
                }
            });
        }
    }
});
